/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBean;

import bean.business.classBean;
import bean.business.curriculumBean;
import bean.business.semesterBean;
import bean.business.stuDetailBean;
import bean.business.studentBean;
import bean.business.subjectBean;
import entities.Classes;
import entities.Curriculum;
import entities.Semester;
import entities.StuDetail;
import entities.Subject;
import java.util.LinkedList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author HoangHai
 */
@ManagedBean
@SessionScoped
public class manageMark {
    @EJB
    private subjectBean subjectBean;
    @EJB
    private studentBean studentBean;
    @EJB
    private stuDetailBean stuDetailBean;
    @EJB
    private classBean classBean;
    @EJB
    private semesterBean semesterBean;
    @EJB
    private curriculumBean curriculumBean;
    private List<Curriculum> cur = new LinkedList<Curriculum>();
    private List<Semester> sem = new LinkedList<Semester>();
    private List<Classes> listCl = new LinkedList<Classes>();
    private List<Subject> sub = new LinkedList<Subject>();
    private List<StuDetail> lstd;
    private StuDetail detail = new StuDetail();

    public StuDetail getDetail() {
        return detail;
    }

    public void setDetail(StuDetail detail) {
        this.detail = detail;
    }

    public List<StuDetail> getLstd() {
        return lstd;
    }

    public void setLstd(List<StuDetail> lstd) {
        this.lstd = lstd;
    }
    public List<Subject> getSub() {
        return sub = subjectBean.allSubject();
    }

    public void setSub(List<Subject> sub) {
        this.sub = sub;
    }

    
    private int curID;
    private int semID;
    private int classID;
    private int subID;
    private String stuID;

    public String getStuID() {
        return stuID;
    }

    public void setStuID(String stuID) {
        this.stuID = stuID;
    }
    private boolean isEdit;

    public boolean isIsEdit() {
        return isEdit;
    }

    public void setIsEdit(boolean isEdit) {
        this.isEdit = isEdit;
    }
    public int getSubID() {
        return subID;
    }

    public void setSubID(int subID) {
        this.subID = subID;
    }
    
    public int getClassID() {
        return classID;
    }

    public void setClassID(int classID) {
        this.classID = classID;
    }

    public List<Classes> getListCl() {
        return listCl = classBean.allClasses();
    }

    public void setListCl(List<Classes> listCl) {
        this.listCl = listCl;
    }

    public List<Curriculum> getCur() {
        return cur = curriculumBean.allCurriculum();
    }

    public void setCur(List<Curriculum> cur) {
        this.cur = cur;
    }

    public int getCurID() {
        return curID;
    }

    public void setCurID(int curID) {
        this.curID = curID;
    }

    public List<Semester> getSem() {
        return sem;
    }

    public void setSem(List<Semester> sem) {
        this.sem = sem;
    }

    public int getSemID() {
        return semID;
    }

    public void setSemID(int semID) {
        this.semID = semID;
    }
    
    /** Creates a new instance of manageMark */
    public manageMark() {
        
    }
    public void findStuByClassIDandSubID(){
        lstd = stuDetailBean.findStuByClassIDandSubID(classID, subID);
    }
    public void editMark(){
//        Student s = studentBean.findStudentByID(stuID);
//        Classes c = classBean.findClassByID(classID);
//        Subject s1 = subjectBean.findSubjectByID(subID);
//        detail.setStuID(s);
//        detail.setSubID(s1);
//        detail.setClassID(c);
        //detail = stuDetailBean.findByID(detail.getDeID());
        List<StuDetail> l = stuDetailBean.findBySubID(detail.getSubID().getSubID());
        if (detail.getMark() >= l.get(0).getSubID().getPassMark()) {
            detail.setStatus(1);
        }else{
            detail.setStatus(0);
        }
        stuDetailBean.updateStudentDetail(detail);
    }

}
